<?php
/**
 * created by zzy
 * date: 2018/1/26 14:04
 */
namespace App\Eloquent\Ygt;

use App\Engine\Func;

class LogisticsBill extends DbEloquent{

    protected $table    = 'ygt_logistics_bill';
    public static $tableFieldList   = [
        ['name'=>'id','title'=>'','value'=>0,'is_must'=>0],
        ['name'=>'company_id','title'=>'登录用户异常','value'=>0,'is_must'=>1],
        ['name'=>'notes_id','title'=>'发货记录','value'=>0,'is_must'=>1],
        ['name'=>'money','title'=>'付款金额','value'=>0,'is_must'=>1],
        ['name'=>'username','title'=>'付款人','value'=>0,'is_must'=>0],
        ['name'=>'pay_type','title'=>'付款方式','value'=>0,'is_must'=>1],
        ['name'=>'bank_name','title'=>'银行名称','value'=>'','is_must'=>1],
        ['name'=>'bane_number','title'=>'银行账号','value'=>'','is_must'=>1],
        ['name'=>'pay_time','title'=>'付款日期','value'=>0,'is_must'=>1],
        ['name'=>'img_ids','title'=>'附件图片','value'=>'','is_must'=>0],
    ];

    public static function edit($data,$pk='')
    {
        $id                 = isset($data['id']) ? intval($data['id']) : 0;
        if($id>0){
            $where          = ['id'=>$id];
            $result         = self::updateOneData($where, $data,$pk);
        } else {
            $result         = self::insertOneData($data,$pk);
        }
        return $result;
    }
    public static function getLists($where,$limit='',$offset='')
    {
        $fileds         = 'id,money,pay_type,username,bank_name,bank_number,img_ids,pay_time';
        $orderby        = '';
        $groupby        = '';
        $join           = '';
        $collection     = self::getList($where, $fileds, $limit, $offset, $orderby, $groupby, $join);
        $lists          = $collection->toArray();
        $payTypeArr     = [1=>'现金',2=>'汇款',3=>'承兑汇票'];
        foreach($lists as $key=>$val)
        {
            $payType        = $payTypeArr[$val['pay_type']];
            $imgImg         = Func::getImgUrlByIds($val['img_ids']);
            $lists[$key]['pay_type']    = $payType;
            $lists[$key]['img_img']     = $imgImg;
        }
        return $lists;
    }

}

